/*
 * Flux JavaScript Library
 * Copyright (c) 2010 Leonardo Dutra Constancio
 * MIT License (http://jsflux.googlecode.com/svn/trunk/mit-license.txt)
 */
flux.Sprite = function(img, frameWidth, frameHeight)
{
	if(this instanceof flux.Displayable)
	{
		flux.Displayable.call(this);
		this.setImage(img);

		// internals
		this.frameSequence = [];
		this.frameCoordsX = [];
		this.frameCoordsY = [];
		this.sequenceIndex = 0;
		this.numberFrames = 0;
	}
};

flux.Sprite.prototype = new flux.Displayable();

flux.Sprite.prototype.setImage = function(img, frameWidth, frameHeight)
{
	// super
	this.width = ~~frameWidth;
	this.height = ~~frameHeight;

	//this.img = img instanceof HTMLImageElement ? img : null;
	this.img = /^img$/i.test(img.tagName) ? img : null;
	return this;
	// TODO Sprite.prototype.setImage is not finished
};

flux.Sprite.prototype.getImage = function()
{
	return this.img;
};

flux.Sprite.prototype.doesSizeFit = function()
{
	return this.img ? this.img % this.frameWidth || this.img.height % this.frameHeight : false;
};

flux.Sprite.prototype.paint = function(ctx2d)// TODO ctx2d? Is it a good "name"?
{
	// TODO Sprite.paint
	return this;
};

flux.Sprite.prototype.prevFrame = function()
{
	if(this.sequenceIndex === 0)
	{
		this.sequenceIndex = this.frameSequence.length - 1;
	} else
	{
		this.sequenceIndex--;
	}
	return this;
};

flux.Sprite.prototype.getFrame = function()
{
	return this.sequenceIndex;
};

flux.Sprite.prototype.nextFrame = function()// TODO can optimize Sprite.prototype.nextFrame?
{
	this.sequenceIndex = (this.sequenceIndex + 1) % this.frameSequence.length;
};

flux.Sprite.prototype.getRawFrameCount = function()
{
	return this.numberFrames;
};

flux.Sprite.prototype.getFrameSequenceLength = function()
{
	return this.frameSequence.length;
};

flux.Sprite.prototype.setFrameSequence = function()
{
	// TODO Sprite.setFrameSequence
};
